<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta content="telephone=no" name="format-detection">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <title>AI盯盘助手</title>
    <link rel="stylesheet" href="css/main.css">
    <link rel="stylesheet" href="css/base.css">
    <!-- <link rel="stylesheet" href="css/page.css"> -->
</head>

<body>
    <div id="container">
        <div class="historical_Records">
            <div class="upper_history">
                <div class="title"> <img src="images/icon_up.png" alt=""></div>
                <div class="upper_main">
                    <table class='Records_list'>
                        <thead>
                            <th>名称代码</th>
                            <th>入选时间</th>
                            <th>周期涨跌幅</th>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
                <div class="consultbut">查阅</div>
            </div>
            <div class="lower_stock">
                <div class="title"> <img src="images/icon_all.png" alt=""></div>
                <div class="Records_main">
                    <table class='Records_list'>
                        <thead>
                            <th>名称代码</th>
                            <th>入选时间</th>
                            <th>剔除时间</th>
                            <th>周期涨跌幅</th>
                        </thead>
                        <tbody>

                        </tbody>

                    </table>

                </div>
            </div>
        </div>
        <div class="mask">
            <div class="login">
                <img src="images/close.png" alt="" class="close">
                <div class="fl common-error-tip-box mr5" id="J_loginErrorTip">
                    <span class="common-error-tip"></span>
                </div>
                <div class="name">
                    <span>账号：</span>
                    <input type="text" id='username' class="form-control" placeholder="请输入账号" required="required">
                </div>
                <div class="password">
                    <span>密码：</span>
                    <input type="password" id='password' class="form-control" placeholder="请输入密码" required="required">
                </div>
                <div class="checkbox">
                    <label>
                        <input type="checkbox" checked="true" id="remember">
                        <i class="input-helper" style="font-style: normal;font-size: 0.28rem">
                            自动保存登录信息
                        </i>
                    </label>
                </div>
                <div class="loginbtn">登录</div>
            </div>
        </div>
    </div>
</body>

<script src="js/jquery.js"></script>
<script src="js/rem.js"></script>
<!-- <script src="js/page.js"></script> -->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
    var baseurl = "https://dpb002.applinzi.com",
        islogin = window.localStorage.getItem("loginSign");
    if (islogin == 'true') {
        $('.consultbut').hide();
    }

    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
    var link = window.location.href;
    // 静默登录
    // if (link.indexOf('token') == -1) {
    //     if (!localStorage.getItem('token')) {
    //         var linkUrl = encodeURIComponent(encodeURIComponent(link))
    //         window.location.href = "http://api.fansnew.com/wx/develop/user/jump?back_url=" + linkUrl
    //     }
    // } else {
    //     var token = getQueryString('token');
    //     localStorage.setItem('token', token);
    // }

    // 上架和下架的股票, 上架股票就是当前持仓个股.
    function historical_Records(cb) {
        axios.get(baseurl + '/forward/stockIncubatorData', {
                params: {
                    account: 001
                }
            })
            .then(function(res) {
                cb && cb(res)
            })
            .catch(function(error) {
                console.log(error);
            });
    }

    historical_Records(function(res) {
        // 上架持仓个股
        if (islogin == 'true') {
            var upperstr = "";
            var uppertrList = document.querySelector('.upper_history .upper_main .Records_list tbody');
            var upperhistoryList = res.data.putAwayList;
            for (let i = 0; i < upperhistoryList.length; i++) {
                upperstr += " <tr><td class='firstd'> <span class='name'>" + upperhistoryList[i].name +
                    "</span> <span class='num'>" +
                    upperhistoryList[i].code + "</span> </td> <td>" + upperhistoryList[i].begin_date + "</td> "
                if (upperhistoryList[i].profit >= 0) {
                    upperstr += "<td class = 'lasttd up' > " + upperhistoryList[i].profit + "%</td>"
                } else {
                    upperstr += " <td class = 'lasttd down' > " + upperhistoryList[i].profit + "%</td>"
                }
                upperstr += "</tr>"
            }
            uppertrList.innerHTML = upperstr
        } else {
            var upperstr = "";
            var uppertrList = document.querySelector('.upper_history .upper_main .Records_list tbody');
            var upperhistoryList = res.data.putAwayList;
            for (let i = 0; i < 3; i++) {
                upperstr += " <tr><td class='firstd'>**** </td> <td class = 'lasttd'>****</td><td>****</td> "
                upperstr += "</tr>"
            }
            uppertrList.innerHTML = upperstr
        }

        //插入下架历史记录数据
        var str = "";
        var trList = document.querySelector('.lower_stock .Records_main .Records_list tbody');
        var historyList = res.data.soldOutList;
        for (let i = 0; i < historyList.length; i++) {
            str += " <tr><td class='firstd'> <span class='name'>" + historyList[i].name +
                "</span> <span class='num'>" +
                historyList[i].code + "</span> </td> <td>" + historyList[i].begin_date + "</td> <td>" +
                historyList[i].end_date + "</td> "
            if (historyList[i].profit >= 0) {
                str += "<td class = 'lasttd up' > " + historyList[i].profit + "%</td>"
            } else {
                str += " <td class = 'lasttd down' > " + historyList[i].profit + "%</td>"
            }
            str += "</tr>"
        }
        trList.innerHTML = str
        // $('#pageBar').page({
        //     leng: 66, //分页总数
        //     activeClass: 'activP', //active 类样式定义
        //     clickBack: function (page) {
        //         console.log(page)
        //     }
        // })
        // $('.pageTest').setLength(10)

    })


    // 点击查阅
    $('.consultbut').click(function() {
        $('.mask').show();
    })
    var tip = $(".common-error-tip"),
        username = $('#username'),
        password = $("#password"),
        RememberMe = $("#RememberMe").is(":checked");
    //页面初始化时，如果帐号密码cookie存在则填充
    if (getCookie('user') && getCookie('pswd')) {
        console.log(res)
        username.value = getCookie('user');
        password.value = getCookie('pswd');
        RememberMe.checked = true;
    }
    //复选框勾选状态发生改变时，如果未勾选则清除cookie
    RememberMe.onchange = function() {
        if (!this.checked) {
            delCookie('user');
            delCookie('pswd');
        }
    };
    //设置cookie
    function setCookie(name, value, day) {
        var date = new Date();
        date.setDate(date.getDate() + day);
        document.cookie = name + '=' + value + ';expires=' + date;
    };

    function getCookie(name) {
        var reg = RegExp(name + '=([^;]+)');
        var arr = document.cookie.match(reg);
        if (arr) {
            return arr[1];
        } else {
            return '';
        }
    };

    function checkUserName() {
        var usernameval = username.val();
        if ($.trim(usernameval).length === 0) {
            tip.text("请输入用户名！");
            // $('#username.form-control').addClass('act')
            return false;
        }
        // $('#username.form-control').removeClass('act')
        return true;
    };

    function checkPassword() {
        var passwordval = password.val();
        if ($.trim(passwordval).length === 0) {
            tip.text("请输入密码！");
            // $('#password.form-control').addClass('act')
            return false;
        }
        // $('#username.form-control').removeClass('act')
        return true;
    };


    function LoginInfor() {
        if (!checkUserName()) {
            return;
        }
        if (!checkPassword()) {
            return;
        }
        axios.get(baseurl + '/forward/checkPassword', {
                params: {
                    mobile_phone: username.val(),
                    new_password: password.val(),
                    channel: '001',
                }
            })
            .then(function(res) {
                if (res.data.status == 0) {
                    tip.text(res.data.message);
                }
                if (res.data.status == 1) {
                    // window.localStorage.setItem('loginSign', true)
                    $('.mask').hide();
                    window.location.reload();
                    window.localStorage.setItem('loginSign', true)
                    if (remember.checked) {
                        //如果选中就建立缓存
                        setCookie('user', username.value); //保存帐号到cookie，有效期7天
                        setCookie('pswd', password.value); //保存密码到cookie，有效期7天
                    }
                }
            })
            .catch(function(res) {});
    }
    $('.close').click(function() {
        $('.mask').hide();
    })
    $(".loginbtn").on("click", LoginInfor)
</script>

</html>